
package org.itboys.mobile.service;

import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.mongo.SundayMember;
import org.itboys.mobile.service.mongo.web.SundayMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 作者：jiangxiong
 * 日期：2017年5月8日
 * 联系方式 ：empty90911@126.com
 * 描述：圣代_项目自动任务_权限。
 *
 */

@Service
public class SundayJobService {
	@Autowired
	private SundayMemberService memberService;


	public void deadMember(){
		Map<String,Object> param = new HashMap<String,Object>();
		param.put("isDeleted", SundayCommonConstants.NO);
		param.put("userType in",new Integer[]{SundayCommonConstants.user_type_person,SundayCommonConstants.user_type_business});
		List<SundayMember> members = memberService.list(param);
		Long now = Calendar.getInstance().getTimeInMillis();
		List<SundayMember> isNeedToDead = new ArrayList<>();
		for(SundayMember member:members){
			if(member.getDeadTime()!=null&&now>member.getDeadTime()){
				member.setUserType(SundayCommonConstants.user_type_member);
				isNeedToDead.add(member);
			}
		}
		if(ListUtil.isNotNull(isNeedToDead)){
			memberService.batchUpdateWithoutLogin(isNeedToDead);
		}
	}


}